package cn.javabb.log.action;

import cn.hutool.core.util.StrUtil;
import cn.javabb.core.entity.sys.LogDO;
import cn.javabb.log.action.base.BaseActionMap;
import cn.javabb.log.action.base.ResetLog;
import cn.javabb.log.action.model.BizMethod;
import lombok.extern.slf4j.Slf4j;

/**
 * @desc:
 * @author: javabb (javabob(a)163.com)
 * @create: 2019/10/28 17:16
 */
@Slf4j
public class DeleteAction extends BaseActionMap {
    public static final String LOG_DELETE_CLEAR = "log_clear";
    @Override
    public void init() {
        // 记录数据保存日志
        putMethod("default","defaultMethod");

        putMethod(LOG_DELETE_CLEAR,new BizMethod("日志清除","clearMethod"));
    }

    /**
     * 重新包装删除数据行为方法
     * 接收参数必须是ids
     * @param resetLog ResetLog对象数据
     */
    @SuppressWarnings("unchecked")
    public static void defaultMethod(ResetLog resetLog) {
        if(resetLog.isSuccessRecord()){
            //String state = (String) resetLog.getParam("state");
            String ids =  String.valueOf(resetLog.getParam("ids"));
            if(StrUtil.isNotBlank(ids)){
                resetLog.getLog().setMessage("删除ID：" + ids);
                return;
            }
            String id =  String.valueOf(resetLog.getParam("id"));
            if(StrUtil.isNotBlank(id)){
                resetLog.getLog().setMessage("删除ID：" + id);
            }
        }
    }
    /**
     * 清除
     */
    public void clearMethod(ResetLog resetLog){
        LogDO logDO = resetLog.getLog();
        if (resetLog.isSuccess()){
            logDO.setMessage("日志清除成功。");
        }else {
            logDO.setMessage("日志清除失败");
        }
    }
}
